package tcln.sors.model.order.dom;

import java.util.Date;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.validator.Min;
import org.hibernate.validator.NotNull;

import tcln.sors.model.base.dom.AbstractSorsNamedEntity;
import tcln.sors.model.base.dom.DeliverableEntity;
import tcln.sors.model.contact.dom.Contact;

/**
 * @author Truong Chau Lien Ngoc (lienngoc@gmail.com)
 */
@Entity
@Table(name = "TBL_ORDER")
@AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "ORDER_ID")) })
public class Order extends AbstractSorsNamedEntity implements DeliverableEntity {
    private static final long serialVersionUID = 1L;

    private Contact customer;
    private Date deliveryDate;
    private Date creationDate;
    private Date expiryDate;
    private Integer remindBefore;
    private OrderStatus status = OrderStatus.PREPARING;

    /**
     * Returns current value of {@link #customer}.
     * 
     * @return the {@link #customer}.
     */
    @ManyToOne
    @JoinColumn(name = "CONTACT_ID", nullable = false)
    @NotNull
    public Contact getCustomer() {
        return customer;
    }

    /**
     * Sets new value for {@link #customer}.
     * 
     * @param customer
     *            the new customer to set
     */
    public void setCustomer(Contact customer) {
        this.customer = customer;
    }

    /**
     * {@inheritDoc}
     */
    @Temporal(TemporalType.DATE)
    @Column(name = "DELIVERY_DATE")
    public Date getDeliveryDate() {
        return deliveryDate;
    }

    /**
     * {@inheritDoc}
     */
    public void setDeliveryDate(Date deliveryDate) {
        this.deliveryDate = deliveryDate;
    }

    /**
     * {@inheritDoc}
     */
    @NotNull
    @Temporal(TemporalType.DATE)
    @Column(name = "CREATION_DATE")
    public Date getCreationDate() {
        return creationDate;
    }

    /**
     * {@inheritDoc}
     */
    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    /**
     * {@inheritDoc}
     */
    @NotNull
    @Temporal(TemporalType.DATE)
    @Column(name = "EXPIRY_DATE")
    public Date getExpiryDate() {
        return expiryDate;
    }

    /**
     * {@inheritDoc}
     */
    public void setExpiryDate(Date expiryDate) {
        this.expiryDate = expiryDate;
    }

    /**
     * {@inheritDoc}
     */
    @Min(1)
    @Column(name = "REMIND_BEFORE")
    public Integer getRemindBefore() {
        return remindBefore;
    }

    /**
     * {@inheritDoc}
     */
    public void setRemindBefore(Integer remindBefore) {
        this.remindBefore = remindBefore;
    }

    /**
     * Returns current value of {@link #status}.
     * 
     * @return the {@link #status}.
     */
    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "STATUS")
    public OrderStatus getStatus() {
        return status;
    }

    /**
     * Sets new value for {@link #status}.
     * 
     * @param status
     *            the new status to set
     */
    public void setStatus(OrderStatus status) {
        this.status = status;
    }
}
